package com.ksd.pug.controller.banner;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ksd.pug.commons.anno.PugLog;
import com.ksd.pug.commons.anno.PugPermissionIngore;
import com.ksd.pug.commons.enums.ResultStatusEnumA;
import com.ksd.pug.commons.ex.PugValidationException;
import com.ksd.pug.commons.utils.fn.asserts.Vsserts;
import com.ksd.pug.config.anno.LoginCheck;
import com.ksd.pug.controller.BaseController;
import com.ksd.pug.pojo.Banner;
import com.ksd.pug.service.banner.IBannerService;
import com.ksd.pug.vo.BannerVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * BannerController
 * 创建人:hcl<br/>
 * @version 1.0.0<br/>
 *
*/

@RestController
@RequiredArgsConstructor
@Slf4j
public class BannerController extends BaseController{

    private final IBannerService bannerService;


    /**
     * 查询轮播图列表信息
     * 创建人:hcl
     * 创建时间：2022-02-21 15:05:53
     * @version 1.0.0
     * @return
     */
    @LoginCheck
    @GetMapping("/banner/load")
    @PugPermissionIngore
    public List<Banner> findBannerList() {
        return bannerService.findBannerList();
    }

	/**
	 * 查询轮播图列表信息并分页
	 * 创建人:hcl
	 * 创建时间：2022-02-21 15:05:53
	 * @version 1.0.0
	*/
    @LoginCheck
    @PugPermissionIngore
    @PostMapping("/banner/list")
    public IPage<Banner> findBanners(@RequestBody BannerVo bannerVo) {
        return bannerService.findBannerPage(bannerVo);
    }


    /**
     * 根据轮播图id查询明细信息
     * 创建人:hcl
     * 创建时间：2022-02-21 15:05:53
     * @version 1.0.0
    */
    @GetMapping("/banner/get/{id}")
    public Banner getBannerById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
           throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return bannerService.getBannerById(new Long(id));
    }


	/**
	 * 保存和修改轮播图
	 * 创建人:hcl
	 * 创建时间：2022-02-21 15:05:53
	 * @version 1.0.0
	*/
    @PostMapping("/banner/saveupdate")
    @PugLog(title = "保存或修改轮播图")
    public Banner saveupdateBanner(@RequestBody Banner banner) {
        return bannerService.saveupdateBanner(banner);
    }


    /**
	 * 根据轮播图id删除轮播图
	 * 创建人:hcl
	 * 创建时间：2022-02-21 15:05:53
	 * @version 1.0.0
	*/
    @PostMapping("/banner/delete/{id}")
    public int deleteBannerById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return bannerService.deleteBannerById(new Long(id));
    }


   /**
   	 * 根据轮播图ids批量删除轮播图
   	 * 创建人:hcl
   	 * 创建时间：2022-02-21 15:05:53
   	 * @version 1.0.0
   	*/
    @PostMapping("/banner/delBatch")
    public boolean delBanner(@RequestBody BannerVo bannerVo) {
        log.info("你要批量删除的IDS是:{}", bannerVo.getBatchIds());
        if (Vsserts.isEmpty(bannerVo.getBatchIds())) {
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return bannerService.delBatchBanner(bannerVo.getBatchIds());
    }

}